<template>
	<view class="img-upload-container">
		<image class="img" :src="imgUrl[0]" mode="aspectFill" @click="imgUpload"></image>
		<button @click="imgUpload">上传图片</button>
		<button @click="previewImage">图片预览</button>
		<button @click="getImgInfo">获取图片信息</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl:["/static/logo.png"]
			}
		},
		methods: {
			imgUpload(){
				uni.chooseImage({
					count:1,
					success: (res) => {
						console.log(JSON.stringify(res));
						
						uni.previewImage({
							urls:res.tempFilePaths
						})
						
						this.imgUrl = res.tempFilePaths;
					}
				})
			},
			previewImage(){
					uni.previewImage({
						urls:this.imgUrl
					})
			},
			getImgInfo(){
				uni.getImageInfo({
					src:this.imgUrl[0],
					success: (res) => {
						console.log(res);
					}
				})
			}
		}
	}
</script>

<style>
	.img-upload-container {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.img {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
	}
		
	.img-upload-container>button{
		margin-top: 20rpx;
	}
</style>